package com.weishi.project.sport.trainingdata.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.weishi.common.enums.TrainingProgramEnum;
import com.weishi.common.utils.StringUtils;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.project.sport.trainingdata.service.TrainingDataService;
import com.weishi.project.sport.trainingdata.vo.*;
import com.weishi.project.sport.util.PageUtil;
import com.weishi.project.system.service.ISysDictDataService;
import com.weishi.project.system.service.ISysDictTypeService;
import com.weishi.project.training.domain.LeaveForm;
import com.weishi.project.training.domain.NaturalYear;
import com.weishi.project.training.domain.TrainingAchievement;
import com.weishi.project.training.domain.TrainingDay;
import com.weishi.project.training.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 运动员 训练数据模块 接口 实现类
 */
@Service
public class TrainingDataServiceImpl implements TrainingDataService {


    /**
     * 训练成绩 接口
     */
    @Autowired
    private ITrainingAchievementService trainingAchievementService;

    /**
     * 日训练成绩 接口
     */
    @Autowired
    private ITrainingDayService trainingDayService;

    /**
     * 训练分组 接口
     */
    @Autowired
    private ITrainingGroupService trainingGroupService;

    /**
     * 请假表 接口
     */
    @Autowired
    private ILeaveFormService leaveFormService;

    /**
     * 自然年接口
     */
    @Autowired
    private INaturalYearService naturalYearService;

    /**
     * 数据字典 主表接口
     */
    @Autowired
    private ISysDictTypeService dictTypeService;

    /**
     * 数据字典 子表接口
     */
    @Autowired
    private ISysDictDataService dictDataService;



    /**
     * 封装方法 根据 年 查询 12 个月的统计时间
     */
    public ReturnMonthVO getMonth(Integer userId , String years , List<String> dayList){
        // 封装查询返回值  根据传参-年-查询所有月的统计 ( 按照 分钟 统计 )
        ReturnMonthVO returnMonthVO = new ReturnMonthVO();
        // 查询 1 月份统计时间
        returnMonthVO.setJanuary(trainingDayService.getPrepareMonth(userId , years+"-01" , dayList));

        // 查询 2 月份统计时间
        returnMonthVO.setFebruary(trainingDayService.getPrepareMonth(userId , years+"-02" , dayList));

        // 查询 3 月份统计时间
        returnMonthVO.setMarch(trainingDayService.getPrepareMonth(userId , years+"-03" , dayList));

        // 查询 4 月份统计时间
        returnMonthVO.setApril(trainingDayService.getPrepareMonth(userId , years+"-04" , dayList));

        // 查询 5 月份统计时间
        returnMonthVO.setMay(trainingDayService.getPrepareMonth(userId , years+"-05" , dayList));

        // 查询 6 月份统计时间
        returnMonthVO.setJune(trainingDayService.getPrepareMonth(userId , years+"-06" , dayList));

        // 查询 7 月份统计时间
        returnMonthVO.setJuly(trainingDayService.getPrepareMonth(userId , years+"-07" , dayList));

        // 查询 8 月份统计时间
        returnMonthVO.setAugust(trainingDayService.getPrepareMonth(userId , years+"-08" , dayList));

        // 查询 9 月份统计时间
        returnMonthVO.setSeptember(trainingDayService.getPrepareMonth(userId , years+"-09" , dayList));

        // 查询 10 月份统计时间
        returnMonthVO.setOctober(trainingDayService.getPrepareMonth(userId , years+"-10" , dayList));

        // 查询 11 月份统计时间
        returnMonthVO.setNovember(trainingDayService.getPrepareMonth(userId , years+"-11" , dayList));

        // 查询 12 月份统计时间
        returnMonthVO.setDecember(trainingDayService.getPrepareMonth(userId , years+"-12" , dayList));

        return returnMonthVO;
    }

    /**
     * 查询返回值  一年中 二级科目的时间占比
     */
    public ReturnLevelTwoVO queryLevelTwoVO(Integer userId , String years , List<String> dayList){
        // 封装查询返回值  一年中 二级科目的时间占比
        ReturnLevelTwoVO returnLevelTwoVO = new ReturnLevelTwoVO();

        // 查询 1 月份统计时间
        physicalTrainingLevelTwoVO january = new physicalTrainingLevelTwoVO();

        // 1月的球类活动
        String ballGames = TrainingProgramEnum.BALL_GAMES.getKey();
        january.setBallGames(trainingDayService.getReturnLevelTwoVO(userId , years+"01" , ballGames , dayList));

        // 1月的徒手活动
        String uinarmedActivities = TrainingProgramEnum.UINARMED_ACTIVITIES.getKey();
        january.setUinarmedActivities(trainingDayService.getReturnLevelTwoVO(userId , years+"01" , uinarmedActivities , dayList));

        // 1月的动态拉伸
        String dynamicStretching = TrainingProgramEnum.DYNAMIC_STRETCHING.getKey();
        january.setDynamicStretching(trainingDayService.getReturnLevelTwoVO(userId , years+"01" , dynamicStretching , dayList));

        // 1 月的 其他
        String other = TrainingProgramEnum.OTHER.getKey();
        january.setOther(trainingDayService.getReturnLevelTwoVO(userId , years+"01" , other , dayList));

        // 1 月的 原地动态拉伸
        String dynamicStretchInPlace = TrainingProgramEnum.DYNAMIC_STRETCH_IN_PLACE.getKey();
        january.setDynamicStretchInPlace(trainingDayService.getReturnLevelTwoVO(userId , years+"01" , dynamicStretchInPlace , dayList));

        // 1 月的 行进间准备活动
        String warmUp = TrainingProgramEnum.WARM_UP.getKey();
        january.setWarmUp(trainingDayService.getReturnLevelTwoVO(userId , years+"01" , warmUp , dayList));


        // 查询 2 月份统计时间
        physicalTrainingLevelTwoVO february = new physicalTrainingLevelTwoVO();

        // 2月的球类活动
        String ballGamesTwo = TrainingProgramEnum.BALL_GAMES.getKey();
        february.setBallGames(trainingDayService.getReturnLevelTwoVO(userId , years+"02" , ballGamesTwo , dayList));

        // 2月的徒手活动
        String uinarmedActivitiesTwo = TrainingProgramEnum.UINARMED_ACTIVITIES.getKey();
        february.setUinarmedActivities(trainingDayService.getReturnLevelTwoVO(userId , years+"02" , uinarmedActivitiesTwo , dayList));

        // 2月的动态拉伸
        String dynamicStretchingTwo = TrainingProgramEnum.DYNAMIC_STRETCHING.getKey();
        february.setDynamicStretching(trainingDayService.getReturnLevelTwoVO(userId , years+"02" , dynamicStretchingTwo , dayList));

        // 2 月的 其他
        String otherTwo = TrainingProgramEnum.OTHER.getKey();
        february.setOther(trainingDayService.getReturnLevelTwoVO(userId , years+"02" , otherTwo , dayList));

        // 2 月的 原地动态拉伸
        String dynamicStretchInPlaceTwo = TrainingProgramEnum.DYNAMIC_STRETCH_IN_PLACE.getKey();
        february.setDynamicStretchInPlace(trainingDayService.getReturnLevelTwoVO(userId , years+"02" , dynamicStretchInPlaceTwo , dayList));

        // 2 月的 行进间准备活动
        String warmUpTwo = TrainingProgramEnum.WARM_UP.getKey();
        february.setWarmUp(trainingDayService.getReturnLevelTwoVO(userId , years+"02" , warmUpTwo , dayList));


        // 查询 3 月份统计时间
        physicalTrainingLevelTwoVO march = new physicalTrainingLevelTwoVO();

        // 3月的球类活动
        String ballGamesMarch = TrainingProgramEnum.BALL_GAMES.getKey();
        march.setBallGames(trainingDayService.getReturnLevelTwoVO(userId , years+"03" , ballGamesMarch , dayList));

        // 3月的徒手活动
        String uinarmedActivitiesMarch = TrainingProgramEnum.UINARMED_ACTIVITIES.getKey();
        march.setUinarmedActivities(trainingDayService.getReturnLevelTwoVO(userId , years+"03" , uinarmedActivitiesMarch , dayList));

        // 3月的动态拉伸
        String dynamicStretchingMarch = TrainingProgramEnum.DYNAMIC_STRETCHING.getKey();
        march.setDynamicStretching(trainingDayService.getReturnLevelTwoVO(userId , years+"03" , dynamicStretchingMarch , dayList));

        // 3 月的 其他
        String otherMarch = TrainingProgramEnum.OTHER.getKey();
        march.setOther(trainingDayService.getReturnLevelTwoVO(userId , years+"03" , otherMarch , dayList));

        // 3 月的 原地动态拉伸
        String dynamicStretchInPlaceMarch = TrainingProgramEnum.DYNAMIC_STRETCH_IN_PLACE.getKey();
        march.setDynamicStretchInPlace(trainingDayService.getReturnLevelTwoVO(userId , years+"03" , dynamicStretchInPlaceMarch , dayList));

        // 3 月的 行进间准备活动
        String warmUpMarch = TrainingProgramEnum.WARM_UP.getKey();
        march.setWarmUp(trainingDayService.getReturnLevelTwoVO(userId , years+"03" , warmUpMarch , dayList));


        // 查询 4 月份统计时间
        physicalTrainingLevelTwoVO april = new physicalTrainingLevelTwoVO();

        // 4月的球类活动
        String ballGamesApril = TrainingProgramEnum.BALL_GAMES.getKey();
        april.setBallGames(trainingDayService.getReturnLevelTwoVO(userId , years+"04" , ballGamesApril , dayList));

        // 4月的徒手活动
        String uinarmedActivitiesApril = TrainingProgramEnum.UINARMED_ACTIVITIES.getKey();
        april.setUinarmedActivities(trainingDayService.getReturnLevelTwoVO(userId , years+"04" , uinarmedActivitiesApril , dayList));

        // 4月的动态拉伸
        String dynamicStretchingApril = TrainingProgramEnum.DYNAMIC_STRETCHING.getKey();
        april.setDynamicStretching(trainingDayService.getReturnLevelTwoVO(userId , years+"04" , dynamicStretchingApril , dayList));

        // 4 月的 其他
        String otherApril = TrainingProgramEnum.OTHER.getKey();
        april.setOther(trainingDayService.getReturnLevelTwoVO(userId , years+"04" , otherApril , dayList));

        // 4 月的 原地动态拉伸
        String dynamicStretchInPlaceApril = TrainingProgramEnum.DYNAMIC_STRETCH_IN_PLACE.getKey();
        april.setDynamicStretchInPlace(trainingDayService.getReturnLevelTwoVO(userId , years+"04" , dynamicStretchInPlaceApril , dayList));

        // 4 月的 行进间准备活动
        String warmUpApril = TrainingProgramEnum.WARM_UP.getKey();
        april.setWarmUp(trainingDayService.getReturnLevelTwoVO(userId , years+"04" , warmUpApril , dayList));


        // 查询 5 月份统计时间
        physicalTrainingLevelTwoVO may = new physicalTrainingLevelTwoVO();

        // 5月的球类活动
        String ballGamesMay = TrainingProgramEnum.BALL_GAMES.getKey();
        may.setBallGames(trainingDayService.getReturnLevelTwoVO(userId , years+"05" , ballGamesMay , dayList));

        // 5月的徒手活动
        String uinarmedActivitiesMay = TrainingProgramEnum.UINARMED_ACTIVITIES.getKey();
        may.setUinarmedActivities(trainingDayService.getReturnLevelTwoVO(userId , years+"05" , uinarmedActivitiesMay , dayList));

        // 5月的动态拉伸
        String dynamicStretchingMay = TrainingProgramEnum.DYNAMIC_STRETCHING.getKey();
        may.setDynamicStretching(trainingDayService.getReturnLevelTwoVO(userId , years+"05" , dynamicStretchingMay , dayList));

        // 5 月的 其他
        String otherMay = TrainingProgramEnum.OTHER.getKey();
        may.setOther(trainingDayService.getReturnLevelTwoVO(userId , years+"05" , otherMay , dayList));

        // 5 月的 原地动态拉伸
        String dynamicStretchInPlaceMay = TrainingProgramEnum.DYNAMIC_STRETCH_IN_PLACE.getKey();
        may.setDynamicStretchInPlace(trainingDayService.getReturnLevelTwoVO(userId , years+"05" , dynamicStretchInPlaceMay , dayList));

        // 5 月的 行进间准备活动
        String warmUpMay = TrainingProgramEnum.WARM_UP.getKey();
        may.setWarmUp(trainingDayService.getReturnLevelTwoVO(userId , years+"05" , warmUpMay , dayList));


        // 查询 6 月份统计时间
        physicalTrainingLevelTwoVO june = new physicalTrainingLevelTwoVO();

        // 6月的球类活动
        String ballGamesJune = TrainingProgramEnum.BALL_GAMES.getKey();
        june.setBallGames(trainingDayService.getReturnLevelTwoVO(userId , years+"06" , ballGamesJune , dayList));

        // 6月的徒手活动
        String uinarmedActivitiesJune = TrainingProgramEnum.UINARMED_ACTIVITIES.getKey();
        june.setUinarmedActivities(trainingDayService.getReturnLevelTwoVO(userId , years+"06" , uinarmedActivitiesJune , dayList));

        // 6月的动态拉伸
        String dynamicStretchingJune = TrainingProgramEnum.DYNAMIC_STRETCHING.getKey();
        june.setDynamicStretching(trainingDayService.getReturnLevelTwoVO(userId , years+"06" , dynamicStretchingJune , dayList));

        // 6 月的 其他
        String otherJune = TrainingProgramEnum.OTHER.getKey();
        june.setOther(trainingDayService.getReturnLevelTwoVO(userId , years+"06" , otherJune , dayList));

        // 6 月的 原地动态拉伸
        String dynamicStretchInPlaceJune = TrainingProgramEnum.DYNAMIC_STRETCH_IN_PLACE.getKey();
        june.setDynamicStretchInPlace(trainingDayService.getReturnLevelTwoVO(userId , years+"06" , dynamicStretchInPlaceJune , dayList));

        // 6 月的 行进间准备活动
        String warmUpJune = TrainingProgramEnum.WARM_UP.getKey();
        june.setWarmUp(trainingDayService.getReturnLevelTwoVO(userId , years+"06" , warmUpJune , dayList));


        // 查询 7 月份统计时间
        physicalTrainingLevelTwoVO july = new physicalTrainingLevelTwoVO();

        // 7月的球类活动
        String ballGamesJuly = TrainingProgramEnum.BALL_GAMES.getKey();
        july.setBallGames(trainingDayService.getReturnLevelTwoVO(userId , years+"07" , ballGamesJuly , dayList));

        // 7月的徒手活动
        String uinarmedActivitiesJuly = TrainingProgramEnum.UINARMED_ACTIVITIES.getKey();
        july.setUinarmedActivities(trainingDayService.getReturnLevelTwoVO(userId , years+"07" , uinarmedActivitiesJuly , dayList));

        // 7月的动态拉伸
        String dynamicStretchingJuly = TrainingProgramEnum.DYNAMIC_STRETCHING.getKey();
        july.setDynamicStretching(trainingDayService.getReturnLevelTwoVO(userId , years+"07" , dynamicStretchingJuly , dayList));

        // 7 月的 其他
        String otherJuly = TrainingProgramEnum.OTHER.getKey();
        july.setOther(trainingDayService.getReturnLevelTwoVO(userId , years+"07" , otherJuly , dayList));

        // 7 月的 原地动态拉伸
        String dynamicStretchInPlaceJuly = TrainingProgramEnum.DYNAMIC_STRETCH_IN_PLACE.getKey();
        july.setDynamicStretchInPlace(trainingDayService.getReturnLevelTwoVO(userId , years+"07" , dynamicStretchInPlaceJuly , dayList));

        // 7 月的 行进间准备活动
        String warmUpJuly = TrainingProgramEnum.WARM_UP.getKey();
        july.setWarmUp(trainingDayService.getReturnLevelTwoVO(userId , years+"07" , warmUpJuly , dayList));


        // 查询 8 月份统计时间
        physicalTrainingLevelTwoVO august = new physicalTrainingLevelTwoVO();

        // 8月的球类活动
        String ballGamesAugust = TrainingProgramEnum.BALL_GAMES.getKey();
        august.setBallGames(trainingDayService.getReturnLevelTwoVO(userId , years+"08" , ballGamesJuly , dayList));

        // 8月的徒手活动
        String uinarmedActivitiesAugust = TrainingProgramEnum.UINARMED_ACTIVITIES.getKey();
        august.setUinarmedActivities(trainingDayService.getReturnLevelTwoVO(userId , years+"08" , uinarmedActivitiesJuly , dayList));

        // 8月的动态拉伸
        String dynamicStretchingAugust = TrainingProgramEnum.DYNAMIC_STRETCHING.getKey();
        august.setDynamicStretching(trainingDayService.getReturnLevelTwoVO(userId , years+"08" , dynamicStretchingJuly , dayList));

        // 8 月的 其他
        String otherAugust = TrainingProgramEnum.OTHER.getKey();
        august.setOther(trainingDayService.getReturnLevelTwoVO(userId , years+"08" , otherJuly , dayList));

        // 8 月的 原地动态拉伸
        String dynamicStretchInPlaceAugust = TrainingProgramEnum.DYNAMIC_STRETCH_IN_PLACE.getKey();
        august.setDynamicStretchInPlace(trainingDayService.getReturnLevelTwoVO(userId , years+"08" , dynamicStretchInPlaceJuly , dayList));

        // 8 月的 行进间准备活动
        String warmUpAugust = TrainingProgramEnum.WARM_UP.getKey();
        august.setWarmUp(trainingDayService.getReturnLevelTwoVO(userId , years+"08" , warmUpJuly , dayList));


        // 查询 9 月份统计时间
        physicalTrainingLevelTwoVO september = new physicalTrainingLevelTwoVO();

        // 9月的球类活动
        String ballGamesSeptember = TrainingProgramEnum.BALL_GAMES.getKey();
        september.setBallGames(trainingDayService.getReturnLevelTwoVO(userId , years+"09" , ballGamesSeptember , dayList));

        // 9月的徒手活动
        String uinarmedActivitiesSeptember = TrainingProgramEnum.UINARMED_ACTIVITIES.getKey();
        september.setUinarmedActivities(trainingDayService.getReturnLevelTwoVO(userId , years+"09" , uinarmedActivitiesSeptember , dayList));

        // 9月的动态拉伸
        String dynamicStretchingSeptember = TrainingProgramEnum.DYNAMIC_STRETCHING.getKey();
        september.setDynamicStretching(trainingDayService.getReturnLevelTwoVO(userId , years+"09" , dynamicStretchingSeptember , dayList));

        // 9 月的 其他
        String otherSeptember = TrainingProgramEnum.OTHER.getKey();
        september.setOther(trainingDayService.getReturnLevelTwoVO(userId , years+"09" , otherSeptember , dayList));

        // 9 月的 原地动态拉伸
        String dynamicStretchInPlaceSeptember = TrainingProgramEnum.DYNAMIC_STRETCH_IN_PLACE.getKey();
        september.setDynamicStretchInPlace(trainingDayService.getReturnLevelTwoVO(userId , years+"09" , dynamicStretchInPlaceSeptember , dayList));

        // 9 月的 行进间准备活动
        String warmUpSeptember = TrainingProgramEnum.WARM_UP.getKey();
        september.setWarmUp(trainingDayService.getReturnLevelTwoVO(userId , years+"09" , warmUpSeptember , dayList));


        // 查询 10 月份统计时间
        physicalTrainingLevelTwoVO october = new physicalTrainingLevelTwoVO();

        // 10月的球类活动
        String ballGamesOctober = TrainingProgramEnum.BALL_GAMES.getKey();
        october.setBallGames(trainingDayService.getReturnLevelTwoVO(userId , years+"10" , ballGamesOctober , dayList));

        // 10月的徒手活动
        String uinarmedActivitiesOctober = TrainingProgramEnum.UINARMED_ACTIVITIES.getKey();
        october.setUinarmedActivities(trainingDayService.getReturnLevelTwoVO(userId , years+"10" , uinarmedActivitiesOctober , dayList));

        // 10月的动态拉伸
        String dynamicStretchingOctober = TrainingProgramEnum.DYNAMIC_STRETCHING.getKey();
        october.setDynamicStretching(trainingDayService.getReturnLevelTwoVO(userId , years+"10" , dynamicStretchingOctober , dayList));

        // 10 月的 其他
        String otherOctober = TrainingProgramEnum.OTHER.getKey();
        october.setOther(trainingDayService.getReturnLevelTwoVO(userId , years+"10" , otherOctober , dayList));

        // 10 月的 原地动态拉伸
        String dynamicStretchInPlaceOctober = TrainingProgramEnum.DYNAMIC_STRETCH_IN_PLACE.getKey();
        october.setDynamicStretchInPlace(trainingDayService.getReturnLevelTwoVO(userId , years+"10" , dynamicStretchInPlaceOctober , dayList));

        // 10 月的 行进间准备活动
        String warmUpOctober = TrainingProgramEnum.WARM_UP.getKey();
        october.setWarmUp(trainingDayService.getReturnLevelTwoVO(userId , years+"10" , warmUpOctober , dayList));


        // 查询 11 月份统计时间
        physicalTrainingLevelTwoVO november = new physicalTrainingLevelTwoVO();

        // 11月的球类活动
        String ballGamesNovember = TrainingProgramEnum.BALL_GAMES.getKey();
        november.setBallGames(trainingDayService.getReturnLevelTwoVO(userId , years+"11" , ballGamesNovember , dayList));

        // 11月的徒手活动
        String uinarmedActivitiesNovember = TrainingProgramEnum.UINARMED_ACTIVITIES.getKey();
        november.setUinarmedActivities(trainingDayService.getReturnLevelTwoVO(userId , years+"11" , uinarmedActivitiesNovember , dayList));

        // 11月的动态拉伸
        String dynamicStretchingNovember = TrainingProgramEnum.DYNAMIC_STRETCHING.getKey();
        november.setDynamicStretching(trainingDayService.getReturnLevelTwoVO(userId , years+"11" , dynamicStretchingNovember , dayList));

        // 11 月的 其他
        String otherNovember = TrainingProgramEnum.OTHER.getKey();
        november.setOther(trainingDayService.getReturnLevelTwoVO(userId , years+"11" , otherNovember , dayList));

        // 11 月的 原地动态拉伸
        String dynamicStretchInPlaceNovember = TrainingProgramEnum.DYNAMIC_STRETCH_IN_PLACE.getKey();
        november.setDynamicStretchInPlace(trainingDayService.getReturnLevelTwoVO(userId , years+"11" , dynamicStretchInPlaceNovember , dayList));

        // 11 月的 行进间准备活动
        String warmUpNovember = TrainingProgramEnum.WARM_UP.getKey();
        november.setWarmUp(trainingDayService.getReturnLevelTwoVO(userId , years+"11" , warmUpNovember , dayList));


        // 查询 12 月份统计时间
        physicalTrainingLevelTwoVO december = new physicalTrainingLevelTwoVO();

        // 12月的球类活动
        String ballGamesDecember = TrainingProgramEnum.BALL_GAMES.getKey();
        december.setBallGames(trainingDayService.getReturnLevelTwoVO(userId , years+"12" , ballGamesDecember , dayList));

        // 12月的徒手活动
        String uinarmedActivitiesDecember = TrainingProgramEnum.UINARMED_ACTIVITIES.getKey();
        december.setUinarmedActivities(trainingDayService.getReturnLevelTwoVO(userId , years+"12" , uinarmedActivitiesDecember , dayList));

        // 12月的动态拉伸
        String dynamicStretchingDecember = TrainingProgramEnum.DYNAMIC_STRETCHING.getKey();
        december.setDynamicStretching(trainingDayService.getReturnLevelTwoVO(userId , years+"12" , dynamicStretchingDecember , dayList));

        // 12 月的 其他
        String otherDecember = TrainingProgramEnum.OTHER.getKey();
        december.setOther(trainingDayService.getReturnLevelTwoVO(userId , years+"12" , otherDecember , dayList));

        // 12 月的 原地动态拉伸
        String dynamicStretchInPlaceDecember = TrainingProgramEnum.DYNAMIC_STRETCH_IN_PLACE.getKey();
        december.setDynamicStretchInPlace(trainingDayService.getReturnLevelTwoVO(userId , years+"12" , dynamicStretchInPlaceDecember , dayList));

        // 12 月的 行进间准备活动
        String warmUpDecember = TrainingProgramEnum.WARM_UP.getKey();
        december.setWarmUp(trainingDayService.getReturnLevelTwoVO(userId , years+"12" , warmUpDecember , dayList));


        // 存入 1 月统计时间
        returnLevelTwoVO.setJanuaryVO(january);

        // 存入 2 月统计时间
        returnLevelTwoVO.setFebruaryVO(february);

        // 存入 3 月统计时间
        returnLevelTwoVO.setMarchVO(march);

        // 存入 4 月统计时间
        returnLevelTwoVO.setAprilVO(april);

        // 存入 5 月统计时间
        returnLevelTwoVO.setMayVO(may);

        // 存入 6 月统计时间
        returnLevelTwoVO.setJuneVO(june);

        // 存入 7 月统计时间
        returnLevelTwoVO.setJulyVO(july);

        // 存入 8 月统计时间
        returnLevelTwoVO.setAugustVO(august);

        // 存入 9 月统计时间
        returnLevelTwoVO.setSeptemberVO(september);

        // 存入 10 月统计时间
        returnLevelTwoVO.setOctoberVO(october);

        // 存入 11 月统计时间
        returnLevelTwoVO.setNovemberVO(november);

        // 存入 12 月统计时间
        returnLevelTwoVO.setDecemberVO(december);

        return returnLevelTwoVO;
    }

    /**
     * 计算百分比方法
     */
    public static String getPercent(int x, int y) {
        double d1 = x * 1.0;
        double d2 = y * 1.0;
        NumberFormat percentInstance = NumberFormat.getPercentInstance();
        // 设置保留几位小数，这里设置的是保留两位小数
        percentInstance.setMinimumFractionDigits(1);
        return percentInstance.format(d1 / d2);
    }

    /**
     * 根据年 来统计 运动员身体准备训练时间 二级科目 所占的百分比
     */
    public PhysicalStringVO getPhysicalStringVO( Integer userId , String years , List<String> dayList ){

        // 把数据放到 List 中去计算百分比
        List<Integer> phyList = new ArrayList<>();

        // 球类活动
        String ballGamesDecember = TrainingProgramEnum.BALL_GAMES.getKey();
        Integer ballGames = trainingDayService.getStringVO(userId , years , ballGamesDecember , dayList);
        if(ballGames == null){
            phyList.add(0);
        }else{
            phyList.add(Integer.parseInt(trainingDayService.getStringVO(userId , years , ballGamesDecember , dayList).toString()));
        }

        // 徒手活动
        String uinarmedActivitiesDecember = TrainingProgramEnum.UINARMED_ACTIVITIES.getKey();
        Integer uinarmedActivities = trainingDayService.getStringVO(userId , years , uinarmedActivitiesDecember , dayList);
        if(uinarmedActivities == null){
            phyList.add(0);
        }else{
            phyList.add(Integer.parseInt(trainingDayService.getStringVO(userId , years , uinarmedActivitiesDecember , dayList).toString()));
        }

        // 动态拉伸
        String dynamicStretchingDecember = TrainingProgramEnum.DYNAMIC_STRETCHING.getKey();
        Integer dynamicStretching = trainingDayService.getStringVO(userId , years , dynamicStretchingDecember , dayList);
        if(dynamicStretching == null){
            phyList.add(0);
        }else{
            phyList.add(Integer.parseInt(trainingDayService.getStringVO(userId , years , dynamicStretchingDecember , dayList).toString()));
        }

        // 其他
        String otherDecember = TrainingProgramEnum.OTHER.getKey();
        Integer other = trainingDayService.getStringVO(userId , years , otherDecember , dayList);
        if(other == null){
            phyList.add(0);
        }else{
            phyList.add(Integer.parseInt(trainingDayService.getStringVO(userId , years , otherDecember , dayList).toString()));
        }

        // 原地动态拉伸
        String dynamicStretchInPlaceDecember = TrainingProgramEnum.DYNAMIC_STRETCH_IN_PLACE.getKey();
        Integer dynamicStretchIn = trainingDayService.getStringVO(userId , years , dynamicStretchInPlaceDecember , dayList);
        if(dynamicStretchIn == null){
            phyList.add(0);
        }else{
            phyList.add(Integer.parseInt(trainingDayService.getStringVO(userId , years , dynamicStretchInPlaceDecember , dayList).toString()));
        }

        // 行进间准备活动
        String warmUpDecember = TrainingProgramEnum.WARM_UP.getKey();
        Integer warmUp = trainingDayService.getStringVO(userId , years , warmUpDecember , dayList);
        if(warmUp == null){
            phyList.add(0);
        }else{
            phyList.add(Integer.parseInt(trainingDayService.getStringVO(userId , years , warmUpDecember , dayList).toString()));
        }

        // 计算集合数据的总数
        int sum = phyList.stream().mapToInt(value -> value).sum();
        List<String> collect = phyList.stream().map(a -> getPercent(a, sum)).collect(Collectors.toList());

        PhysicalStringVO physicalStringVO = new PhysicalStringVO();
        if(ballGames == null ){
            physicalStringVO.setBallGames("0 %");
        }else{
            physicalStringVO.setBallGames(collect.get(0));
        }

        if(uinarmedActivities == null){
            physicalStringVO.setUinarmedActivities("0 %");
        }else{
            physicalStringVO.setUinarmedActivities(collect.get(1));
        }

        if(dynamicStretching == null){
            physicalStringVO.setDynamicStretching("0 %");
        }else{
            physicalStringVO.setDynamicStretching(collect.get(2));
        }

        if(other == null){
            physicalStringVO.setOther("0 %");
        }else{
            physicalStringVO.setOther(collect.get(3));
        }

        if(dynamicStretchIn == null){
            physicalStringVO.setDynamicStretchInPlace("0 %");
        }else{
            physicalStringVO.setDynamicStretchInPlace(collect.get(4));
        }

        if(warmUp == null){
            physicalStringVO.setWarmUp("0 %");
        }else{
            physicalStringVO.setWarmUp(collect.get(5));
        }

        return physicalStringVO;
    }

    /**
     * 查询运动员身体准备训练--根据传参-年-查询所有月的统计 ( 按照 分钟 统计 )
     */
    @Override
    public AjaxResult getPrepare(String years) {

        // 获取当前登录人 id
        Integer userId = 175;

        // 1，查询当前运动员 请假的时间
        List<String> dayList = new ArrayList<>();
        List<LeaveForm> leaveFormList = leaveFormService.list(Wrappers.<LeaveForm>lambdaQuery()
                .eq(LeaveForm::getSportsmanId , userId));
        if(leaveFormList.size()>0){
            leaveFormList.forEach( p-> {
                dayList.add(p.getEndTime().toString());
            });
        }

        // 2，返回查询的训练时间
        ReturnPhysicalTrainingVo returnPhysicalTrainingVo = new ReturnPhysicalTrainingVo();
        // 存入返回的时间
        returnPhysicalTrainingVo.setReturnMonthVO(this.getMonth(userId , years , dayList));

        // 3，查询身体准备训练的 二级 科目 时间占比
        returnPhysicalTrainingVo.setReturnLevelTwoVO(this.queryLevelTwoVO(userId , years , dayList));

        // 4, 二级科目占比（ 百分比 ）
        returnPhysicalTrainingVo.setPhysicalStringVO(this.getPhysicalStringVO(userId , years , dayList));

        return AjaxResult.success(returnPhysicalTrainingVo);
    }


    /**
     * 查询运动员水上专项训练--最好成绩排名
     */
    @Override
    public AjaxResult getWater(Integer trainingMode , Integer kilometers , Integer pageNum , Integer pageSize , Integer realClassHour) {

        // 获取当前登录人 id
        Integer userId = 175;

        Integer ranking = 0;
        List<WaterRankingVO> waterRankingVOList = new ArrayList<>();
        List<WaterRankingVO> waterRankingVOListTwo = trainingAchievementService.getWaterRankingVO(userId , trainingMode , kilometers , 1 , realClassHour);
        for(int i = 0; i<waterRankingVOListTwo.size(); i++){
            WaterRankingVO waterRankingVO = new WaterRankingVO();
            StringUtils.copyProperties(waterRankingVOListTwo.get(i) , waterRankingVO);
            waterRankingVO.setRanking(ranking+=1);
            waterRankingVOList.add(waterRankingVO);
        }

        if(waterRankingVOList.size() >= pageNum && pageNum != 0){
            return AjaxResult.success(PageUtil.startPage(waterRankingVOList , pageNum , pageSize));
        }else{
            return AjaxResult.success("暂无数据！");
        }
    }


    /**
     * 查询运动员陆上专项训练
     */
    @Override
    public AjaxResult getLand() {
        return null;
    }


    /**
     * 查询运动员陆上力量训练
     */
    @Override
    public AjaxResult getLandStrength() {
        return null;
    }


    /**
     * 查询运动员--训练结果排名--最大力量
     */
    @Override
    public AjaxResult getResultRanking() {
        return null;
    }


    /**
     * 查询运动员--训练数据 模块返回值 （  累计 天 ， 距离 ， 水上训练次数 ， 陆上训练次数  ）
     */
    @Override
    public AjaxResult getReturnTrainingDataVO() {

        // 获取当前登录人 id
        Integer userId = 175;

        //封装返回值数据
        ReturnTrainingDataVO trainingDataVO = new ReturnTrainingDataVO();

        // 1，查询累计天数
        List<Integer> dayId = new ArrayList<>();
        List<TrainingAchievement> trainingAchievementList = trainingAchievementService.list(Wrappers.<TrainingAchievement>lambdaQuery()
                .eq(TrainingAchievement::getSportsmanId , userId));
        if(trainingAchievementList.size()>0){
            trainingAchievementList.forEach( p-> {
                dayId.add(p.getTrainingDayId());
            });
        }

        // 存入累计天数
        if(dayId.size()>0){
            trainingDataVO.setCumulativeDays(trainingDayService.list(Wrappers.<TrainingDay>lambdaQuery()
                    .groupBy(TrainingDay::getDay).in(TrainingDay::getId , dayId)).size());
        }else{
            trainingDataVO.setCumulativeDays(0);
        }

        // 2，查询训练距离，存入训练距离
        if(trainingDayService.getDistance(userId) == null){
            trainingDataVO.setDistance(0);
        }else{
            trainingDataVO.setDistance(trainingDayService.getDistance(userId));
        }

        // 3，查询水上训练次数，存入水上训练次数
        trainingDataVO.setWaterFrequency(trainingDayService.getWaterFrequency(userId));

        // 4，查询陆上训练次数，存入陆上训练次数
        trainingDataVO.setLandNumber(trainingDayService.getLandNumber(userId));

        return AjaxResult.success(trainingDataVO);
    }



    /**
     * 查询自然年 列表
     */
    @Override
    public AjaxResult getNaturalYear() {
        List<NaturalYearVO> naturalYearVOList = new ArrayList<>();
        List<NaturalYear> naturalYearList = naturalYearService.list();
        if(naturalYearList.size()>0){
            naturalYearList.forEach( p-> {
                NaturalYearVO naturalYearVO = new NaturalYearVO();
                StringUtils.copyProperties( p , naturalYearVO);
                naturalYearVOList.add(naturalYearVO);
            });
            return AjaxResult.success(naturalYearVOList);
        }else{
            return AjaxResult.success("暂无数据！");
        }
    }



    /**
     * 查询数据字典主表 -- （ 查询公里数和时间 ）
     */
    @Override
    public AjaxResult getMileageAndTime() {
        return AjaxResult.success(dictTypeService.getMileageAndTime());
    }



    /**
     * 查询数据字典子表 -- （ 根据主表的类型，查询子表的数据 ）
     */
    @Override
    public AjaxResult getTypeValue(String types) {
        return AjaxResult.success(dictDataService.getTypeValue(types));
    }



    /**
     * 查询运动员水上专项训练--训练距离时间
     */
    @Override
    public AjaxResult getTrainingDistanceTime(String years , Integer trainingMode) {

        // 获取当前登录人 id
        Integer userId = 175;

        // 1，查询当前运动员 请假的时间
        List<String> dayList = new ArrayList<>();
        List<LeaveForm> leaveFormList = leaveFormService.list(Wrappers.<LeaveForm>lambdaQuery()
                .eq(LeaveForm::getSportsmanId , userId));
        if(leaveFormList.size()>0){
            leaveFormList.forEach( p-> {
                dayList.add(p.getEndTime().toString());
            });
        }

        //截取字符串 ，只获取 年
        String year = StringUtils.substring(years , 0 , 4);

        TrainingDistanceTimeVO trainingDistanceTimeVO = new TrainingDistanceTimeVO();

        // 水上专项训练 训练距离 统计
        ReturnMonthVO returnMonthVO = new ReturnMonthVO();
        // 1 月统计
        returnMonthVO.setJanuary(trainingDayService.returnMonthVO(year+"-01" , userId , trainingMode , dayList));
        // 2 月统计
        returnMonthVO.setFebruary(trainingDayService.returnMonthVO(year+"-02" , userId , trainingMode , dayList));
        // 3 月统计
        returnMonthVO.setMarch(trainingDayService.returnMonthVO(year+"-03" , userId , trainingMode , dayList));
        // 4 月统计
        returnMonthVO.setApril(trainingDayService.returnMonthVO(year+"-04" , userId , trainingMode , dayList));
        // 5 月统计
        returnMonthVO.setMay(trainingDayService.returnMonthVO(year+"-05" , userId , trainingMode , dayList));
        // 6 月统计
        returnMonthVO.setJune(trainingDayService.returnMonthVO(year+"-06" , userId , trainingMode , dayList));
        // 7 月统计
        returnMonthVO.setJuly(trainingDayService.returnMonthVO(year+"-07" , userId , trainingMode , dayList));
        // 8 月统计
        returnMonthVO.setAugust(trainingDayService.returnMonthVO(year+"-08" , userId , trainingMode , dayList));
        // 9 月统计
        returnMonthVO.setSeptember(trainingDayService.returnMonthVO(year+"-09" , userId , trainingMode , dayList));
        // 10 月统计
        returnMonthVO.setOctober(trainingDayService.returnMonthVO(year+"-10" , userId , trainingMode , dayList));
        // 11 月统计
        returnMonthVO.setNovember(trainingDayService.returnMonthVO(year+"-11" , userId , trainingMode , dayList));
        // 12 月统计
        returnMonthVO.setDecember(trainingDayService.returnMonthVO(year+"-12" , userId , trainingMode , dayList));

        trainingDistanceTimeVO.setReturnMonthVO(returnMonthVO);

        // 水上专项训练 训练时间 滑行距离 统计
        ReturnMonthVO returnMonthTimeVO = new ReturnMonthVO();
        // 1 月统计
        returnMonthTimeVO.setJanuary(trainingDayService.returnMonthTimeVO(year+"-01" , userId , trainingMode , dayList));
        // 2 月统计
        returnMonthTimeVO.setFebruary(trainingDayService.returnMonthTimeVO(year+"-02" , userId , trainingMode , dayList));
        // 3 月统计
        returnMonthTimeVO.setMarch(trainingDayService.returnMonthTimeVO(year+"-03" , userId , trainingMode , dayList));
        // 4 月统计
        returnMonthTimeVO.setApril(trainingDayService.returnMonthTimeVO(year+"-04" , userId , trainingMode , dayList));
        // 5 月统计
        returnMonthTimeVO.setMay(trainingDayService.returnMonthTimeVO(year+"-05" , userId , trainingMode , dayList));
        // 6 月统计
        returnMonthTimeVO.setJune(trainingDayService.returnMonthTimeVO(year+"-06" , userId , trainingMode , dayList));
        // 7 月统计
        returnMonthTimeVO.setJuly(trainingDayService.returnMonthTimeVO(year+"-07" , userId , trainingMode , dayList));
        // 8 月统计
        returnMonthTimeVO.setAugust(trainingDayService.returnMonthTimeVO(year+"-08" , userId , trainingMode , dayList));
        // 9 月统计
        returnMonthTimeVO.setSeptember(trainingDayService.returnMonthTimeVO(year+"-09" , userId , trainingMode , dayList));
        // 10 月统计
        returnMonthTimeVO.setOctober(trainingDayService.returnMonthTimeVO(year+"-10" , userId , trainingMode , dayList));
        // 11 月统计
        returnMonthTimeVO.setNovember(trainingDayService.returnMonthTimeVO(year+"-11" , userId , trainingMode , dayList));
        // 12 月统计
        returnMonthTimeVO.setDecember(trainingDayService.returnMonthTimeVO(year+"-12" , userId , trainingMode , dayList));

        trainingDistanceTimeVO.setReturnMonthTimeVO(returnMonthTimeVO);

        return AjaxResult.success(trainingDistanceTimeVO);
    }









}
